package com.itheima.grow.test;

import com.itheima.grow.model.entity.Question;

import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class StreamTest02 {
    public static void main(String[] args) {
        List<Question> questionList = StreamTest.prepareDate();
        //Step1 filter
        List<Question> filterList = questionList.stream().sorted(Comparator.comparing(Question::getId).reversed()).collect(Collectors.toList());
        for (Question question : filterList) {
            System.out.println(question);
        }
        //Step2 map
        List<String> map = questionList.stream().map(e -> e.getQname()).map(String::trim).distinct().collect(Collectors.toList());
        for (String s : map) {
            System.out.println(s);
        }
        //Step3
        String collect = questionList.stream().map(Question::getQname).map(String::trim).collect(Collectors.joining(","));
        System.out.println(collect);
        //Step3 ToMap
        Map<Integer, Question> questionMap = questionList.stream().filter(e -> e.getId() > 1).collect(Collectors.toMap(Question::getId, q -> q, (k1, k2) -> k2));
        for (Map.Entry<Integer, Question> integerQuestionEntry : questionMap.entrySet()) {
            System.out.println(integerQuestionEntry);
        }
        //Step4 分组
        Map<Integer, List<Question>> collect1 = questionList.stream().collect(Collectors.groupingBy(Question::getId));
    }
}
